﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using emp.BLL;
using emp.Model;
using emp.Utility;

public partial class crm_individuals_CustomersCall : System.Web.UI.Page
{
    IList list = new ArrayList();
            
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack) 
        {
            if (Request.Params["camuid"] != null && Request.Params["camuid"] != "")
            {
                list.Add(Request.Params["camuid"].ToString());
                this.camuid.Value=Request.Params["camuid"].ToString();
                DataTable dt = new emp.BLL.Individuals().getAttachmentByCacuid(list);
                this.datalist.DataSource = dt;
                this.datalist.DataBind();
                PageUtil.setPageCount(datalist, dt.Rows.Count);
                if(dt.Rows.Count>0)
                {
                    this.camnames.Text = dt.Rows[0]["CAM_NAME"].ToString();
                }

            }

            setResult();
            
        }
    }

    protected void datalist_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        list.Clear();
        list.Add(this.camuid.Value);
        datalist.PageIndex = PageUtil.getGviewNewPage(datalist, e.NewPageIndex);

        DataTable dt = getDT();

        this.datalist.DataSource = dt;
        this.datalist.DataBind();
        PageUtil.setPageCount(datalist, dt.Rows.Count);
        setResult();
    }
   
  
    protected void savebt_Click(object sender, EventArgs e)
    {
        DataTable dt = getDT();
        this.datalist.DataSource = dt;
        this.datalist.DataBind();
        PageUtil.setPageCount(datalist, dt.Rows.Count);
        setResult();
    }

    private DataTable getDT() 
    {
        DataTable dt = null;
        if (this.CheckBox2.Checked || this.CheckBox3.Checked || this.CheckBox4.Checked)
        {
            string c2 = "";
            string c3 = "";
            string c4 = "";
            if (this.CheckBox2.Checked)
            {
                c2 = "Y";
            }
            if (this.CheckBox3.Checked)
            {
                c3 = "Y";
            }
            if (this.CheckBox4.Checked)
            {
                c4 = "Y";
            }
            list.Clear();
            list.Add(this.camuid.Value);
            dt = new emp.BLL.Individuals().getAttachmentByCacuid(list, c2, c3, c4);
            
        }
        else
        {
            list.Clear();
            list.Add(this.camuid.Value);
            dt = new emp.BLL.Individuals().getAttachmentByCacuid(list);
            

        }
        return dt;
    }

    private void setResult() 
    {
        for (int i = 0; i < this.datalist.Rows.Count;i++ )
        {
            if (this.datalist.Rows[i].Cells[3].Text=="1")
            {
                this.datalist.Rows[i].Cells[3].Text = "客户放弃购买";
            }
            else if (this.datalist.Rows[i].Cells[3].Text == "2")
            {
                this.datalist.Rows[i].Cells[3].Text = "考虑其它品牌";
            }
            else if (this.datalist.Rows[i].Cells[3].Text == "3")
            {
                this.datalist.Rows[i].Cells[3].Text = "客户自行选择经销商";
            }
            else if (this.datalist.Rows[i].Cells[3].Text == "4")
            {
                this.datalist.Rows[i].Cells[3].Text = "联系信息错误";
            }
            else if (this.datalist.Rows[i].Cells[3].Text == "5")
            {
                this.datalist.Rows[i].Cells[3].Text = "已录入DS-CRM ";
            }
            else 
            {
                this.datalist.Rows[i].Cells[3].Text = "未跟踪 ";
            }

            if (this.datalist.Rows[i].Cells[4].Text=="Y")
            {
                this.datalist.Rows[i].Cells[4].Text = "是";
            }
            else
            {
                this.datalist.Rows[i].Cells[4].Text = "否 ";
            }

        }
    }

}
